package com.semidata.trp.algorithm.main;

import com.semidata.rtd.core.http.server.HttpService;
import com.semidata.rtd.core.log.DefaultLogService;
import com.semidata.rtd.core.log.Logger;
import com.semidata.rtd.core.service.ServiceManager;
import com.semidata.rtd.engine.executor.TaskExecutor;
import com.semidata.trp.algorithm.config.Config;
import com.semidata.trp.algorithm.http.AlgorithmHttpDispatcher;
public class Main {

    private static Config config;

    public static void main(String[] args) {
    	
        String configFile;
        if (args.length > 0) {
            configFile = args[0];
        } else {
            configFile = null;
        }
        
        try {
            Config.init(configFile);
        } catch (RuntimeException e) {
            System.err.println("can not load config file");
            return;
        }
        
        config = Config.getConfig();
        
        ServiceManager.register(new DefaultLogService(config.getLogRoot(), config.isLogDebugEnabled()));
        ServiceManager.register(new TaskExecutor(config.getTaskThreads()));
        
        ServiceManager.register(new HttpService(config.getHttpPort(), config.getHttpThreads(), new AlgorithmHttpDispatcher()));
        ServiceManager.startAll();
        Logger.log("DEBUG", "server started");
        ServiceManager.sync();        
    }

}

